﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using Utils;
using PanasonicWarranty.DAL;
namespace PanasonicWarranty.Business
{
    public partial class pa_Agency
    {
    	#region public properties
		[Required(ErrorMessage="AgencyID Required")]
		public int AgencyID { get; set; }
		[Required(ErrorMessage="Agency Code Required")]
		public string AgencyCode { get; set; }
		public string AgencyName { get; set; }
		public string Address { get; set; }
		public string Email { get; set; }
		public int? ParentID { get; set; }
		public string Level { get; set; }
		public int? Ord { get; set; }
		public bool? Disabled { get; set; }
		#endregion

		#region constructor
		public pa_Agency(){ }

		public pa_Agency(IDataReader rd)
		{
			this.AgencyID = (int)rd["AgencyID"];
			this.AgencyCode = rd["AgencyCode"].ToString();
			this.AgencyName = rd["AgencyName"].ToString();
			this.Address = rd["Address"].ToString();
			this.Email = rd["Email"].ToString();
            this.ParentID = rd["ParentID"].Equals(DBNull.Value) ? (int?)null : (int)rd["ParentID"];
			this.Level = rd["Level"].ToString();
			this.Ord = rd["Ord"].Equals(DBNull.Value) ? (int?)null : (int)rd["Ord"];
			this.Disabled = rd["Disabled"].Equals(DBNull.Value) ? (bool?)null : (bool)rd["Disabled"];
		}
		#endregion

		#region private method
        //private bool Create()
        //{
        //    return DBpa_Agency.Create(AgencyCode, AgencyName, Address, Email, ParentID, Level, Ord, Disabled);
        //}

        private bool Update()
        {
            return DBpa_Agency.Update(AgencyID, AgencyCode, AgencyName, Address, Email, ParentID, Level, Ord, Disabled);
        }
		#endregion

		#region public method
		public bool Save()
		{
            if(AgencyID != 0)
            {
                return Update();
            }
            else
            {
                return Create();
            }
		}
		#endregion

		#region static method
        public static bool Delete(int AgencyID)
        {
            return DBpa_Agency.Delete(AgencyID);
        }

        public static List<pa_Agency> GetAll()
        {
            return ObjectClass.CreateList<pa_Agency>(DBpa_Agency.GetAll());
        }

        public static pa_Agency GetByKey(int AgencyID)
        {
            return ObjectClass.CreateInstance<pa_Agency>(DBpa_Agency.GetByKey(AgencyID));
        }

        public static List<pa_Agency> GetByTop(string top, string where, string order)
        {
            return ObjectClass.CreateList<pa_Agency>(DBpa_Agency.GetByTop(top, where, order));
        }
		#endregion
	}
}
